var app=getApp();
Page({
  data: {
    list:[],
    tabs: [],
    activeIndex: 0,
    sliderOffset: 0,
    sliderLeft: 0,
    locked: false,
  },
  switchByEIndex(number){
    switch (parseInt(number)) {
      case 0:
        return this.data.list0;
      case 1:
        return this.data.list1;
      case 2:
        return this.data.list2;
      case 3:
        return this.data.list3;
    }
  }
,
  onLoad: function () {
    var that = this;
    wx.request({
      url: app.globalData.weburl + app.globalData.jiekou + '/get_news',
      header: { 'content-type': 'application/json' },
      success: function (res) {
        var listlength = res.data.list.length;
        for (var i = 0; i < listlength; i++) {
          if (res.data.list[i].length > 0) {
            var list2length = res.data.list[i].length;
            for (var b = 0; b < list2length; b++) {
              res.data.list[i][b]['images'] = app.globalData.weburl + res.data.list[i][b]['images'];
            }
          }
        }
        that.setData({
          list: res.data.list,
          tabs: res.data.newtype
        });
      }
    })
  },
  tabClick: function (e) {
    if (!this.data.locked) {
      var name = "list" + (e.currentTarget.id).toString()
      var datajson={}
      var temp = Object.assign({},this.switchByEIndex(e.currentTarget.id))
      datajson[name] = {}
      this.setData(Object.assign({}, {
        sliderOffset: e.currentTarget.offsetLeft,
        activeIndex: e.currentTarget.id
      },datajson))
      datajson[name] = temp
      this.setData(datajson)
    }
  }, newitemclick: function (res) {
    console.log(res.currentTarget.dataset.id);

    wx.navigateTo({
      url: '../news/newdetails/newdetails?id=' + res.currentTarget.dataset.id,
    })
  }

})